package com.zl.tby.icc;

import com.zl.tby.core.base.util.ToolsUtil;
import lombok.Data;

import java.util.List;

/**
 * 设备信息
 * @author changpeng
 * @version 1.0
 * @since 2024/9/15 18:13
 */
@Data
public class IccDeviceInfo {
    private String deviceName;
    private String deviceCode;
    private String gpsX;
    private String gpsY;
    /**在线状态，0：离线 1：在线*/
    private Integer isOnline;
    /**设备大类*/
    private Integer deviceCategory;
    /**设备小类*/
    private String deviceType;
    /**设备ip*/
    private String deviceIp;
    private List<IccDeviceUnits> units;

    public String getChannelId() {
        if (units != null && units.size() > 0) {
            List<IccDeviceUnitsChannels> channelList = units.get(0).getChannels();
            if (channelList != null && channelList.size() > 0) {
                return channelList.get(0).getChannelCode();
            }
        }
        return null;
    }

    public String getCameraType() {
        if (units != null && units.size() > 0) {
            List<IccDeviceUnitsChannels> channelList = units.get(0).getChannels();
            if (channelList != null && channelList.size() > 0) {
                return channelList.get(0).getCameraType();
            }
        }
        return null;
    }

    public String getLon() {
        if (this.getGpsX() != null && this.getGpsX().length() > 0) {
            String[] array = ToolsUtil.splitStr(this.getGpsX(), '.');
            String lon = array[0];
            if (array.length > 1 && array[1].length() > 6) {
                lon = lon + "." + array[1].substring(0, 5);
            }
            return this.getGpsX();
        }
        return "";
    }

    public String getLat() {
        if (this.getGpsY() != null && this.getGpsY().length() > 0) {
            String[] array = ToolsUtil.splitStr(this.getGpsY(), '.');
            String lat = array[0];
            if (array.length > 1 && array[1].length() > 6) {
                lat = lat + "." + array[1].substring(0, 5);
            }
            return this.getGpsY();
        }
        return "";
    }
}
